package com.imagination.applet.controller.web.configuration;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class UserHolder {

    public static Long getUserId() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication instanceof JwtToken token) {
            return token.getUserId();
        }
        throw new RuntimeException("to login");
    }

    public static Long getUserIdNotException() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication instanceof JwtToken token) {
            return token.getUserId();
        }
        return null;
    }
}
